/*
 * ShapeButton.fx
 *
 * Created on 16/05/2009, 18:36:26
 */

package webooksfx_desktop.view.components;

import javafx.animation.Timeline;
import javafx.scene.Cursor;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;

/**
 * @author matias
 */

public class AbstractButton extends CustomNode {
	public var x: Integer = 0;
	public var y: Integer = 0;
	public var timeline_button: Timeline = null;
	public var content_button: Node = null;

	public var action: function() : Void;

	var click: Boolean = false;

	public override function create(): Node {
		return Group {
			translateX: bind x
			translateY: bind y
			cursor: Cursor.HAND
			content: bind content_button

            // Manjeadores de eventos sobre el grupo.
            onMousePressed: function( e: MouseEvent ):Void {
                click = true;
            }
            onMouseReleased: function( e: MouseEvent ):Void {
                if (click and hover) {
                    this.action();
                }
                click = false;
            }
            onMouseEntered: function( e: MouseEvent ):Void {
				if (timeline_button != null) {
					timeline_button.rate = 1;
					timeline_button.play();
				}
			}
            onMouseExited: function( e: MouseEvent ):Void {
				if (timeline_button != null) {
					timeline_button.rate = -1;
					timeline_button.play();
				}
			}
		};
	}
}